package com.gw.booking.service;


import com.gw.booking.common.Constant;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by roger on 2017/6/5.
 * 共能服务
 */
@Service
public class CommonService {
    @Autowired
    private SessionFactory sessionFactory;
    @Autowired
    private RandomNumberService randomNumberService;

    /**
     * 生成订单编号
     * @param session
     * @param type
     */
    public String genOrderNo(Session session, String type) {
        String number = randomNumberService.getRandomNumber(session, type);
        String prefix = "";

        if (Constant.ORDER_TYPE_MALL.equals(type)) {
            prefix = "C";
        }
        else if (Constant.ORDER_TYPE_MERCHANT.equals(type)) {
            prefix = "J";
        }
        else if (Constant.ORDER_TYPE_BACK.equals(type)) {
            prefix = "ST";
        }
        else if (Constant.ORDER_TYPE_REFUND.equals(type)) {
            prefix = "SC";
        }

        return prefix + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + number;
    }
}
